def is_prime(n):
    if n <= 1:
        return False
    for i in range(2, int(n**0.5) + 1):
        if n % i == 0:
            return False
    return True

def max_prime(number):
    if len(str(number)) != 4 or number < 1000:
        return 0

    digits = str(number)
    max_prime_num = 0

    for i in range(4):
        for j in range(i + 1, 5):
            num = int(digits[i:j])
            if is_prime(num) and num > max_prime_num:
                max_prime_num = num

        return max_prime_num

number = int(input())
res = max_prime(number)
print(res)
